<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>惰性函数</title>
</head>
<body>
    <button id="btn">点击</button>
</body>
<script>
    const btn = document.getElementById('btn');
    function foo() {
        console.log(this);
    }
    // function addEvent(obj, type, fn) {
    //     if (obj.addEventListener) {
    //         obj.addEventListener(type, fn, false);
    //     } else if (obj.attachEvent) {
    //         obj.attachEvent('on' + type, fn);
    //     } else {
    //         obj['on' + type] = fn;
    //     }
    // }


    function addEvent(obj, type, fn) {
        if (obj.addEventListener) {
            addEvent = obj.addEventListener(type, fn, false);
        } else if (obj.attachEvent) {
            addEvent = obj.attachEvent('on' + type, fn);
        } else {
            addEvent = obj['on' + type] = fn;
        }
    }

    addEvent(btn, 'click', foo);




</script>
</html>